<template>
  <div :style="outModuleCss">
    <div :style="moduleBgCss" class="module-bg"></div>
    <div class="goods-show">
      <div
        :class="[
          'goods-header',
          !propsData.params.showModuleName ? 'add-padding' : '',
        ]"
        v-if="propsData.params.showModuleName"
      >
        <div class="module-header" v-if="propsData.params.showModuleName">
          <p class="module-name" :style="propsData.params.moduleNameCss">
            {{
              propsData.params.showModuleName ? propsData.params.moduleName : ""
            }}
          </p>
          <p
            class="more"
            v-if="propsData.params.showMoreText"
            :style="this.propsData.params.moduleMoreCss"
          >
            <span>{{ propsData.params.moreText || "更多" }}</span>
            <i class="iconfont icon-weibiaoti-13"></i>
          </p>
        </div>
        <div class="item-hover">
          <div class="edit-box" @click.stop="toModuleHeaderControl">
            <i class="iconfont icon-mokuai-bianji"></i>
          </div>
        </div>
        <div
          :style="heaerBgCss"
          v-if="propsData.params.showModuleName"
          class="module-bg"
        ></div>
      </div>
      <div
        class="goods-list"
        :class="styleType == 1 ? 'goods-list-default' : ''"
      >
        <!-- 模板样式1 -->
        <templateDefault
          v-if="styleType == 1"
          :propsData="propsData"
          :goodsItemSpace="goodsItemSpace"
          :goodsList="goodsList"
        ></templateDefault>
        <!-- 模板样式2 -->
        <templateFlexTwo
          v-if="styleType == 2"
          :propsData="propsData"
          :goodsItemSpace="goodsItemSpace"
          :goodsList="goodsList"
        ></templateFlexTwo>
        <!-- 模板样式3 -->
        <templateColumn
          v-if="styleType == 3"
          :propsData="propsData"
          :goodsItemSpace="goodsItemSpace"
          :goodsList="goodsList"
        ></templateColumn>
        <!-- 模板样式4 -->
        <templateGroup
          v-if="styleType == 4"
          :propsData="propsData"
          :goodsItemSpace="goodsItemSpace"
          :goodsList="goodsList"
        ></templateGroup>
        <!-- 模板样式5 -->
        <templateSlide
          v-if="styleType == 5"
          :propsData="propsData"
          :goodsItemSpace="goodsItemSpace"
          :goodsList="goodsList"
        ></templateSlide>
      </div>
    </div>
  </div>
</template>

<script>
import templateDefault from "./templates/default.vue";
import templateFlexTwo from "./templates/flexTwo.vue";
import templateColumn from "./templates/column.vue";
import templateGroup from "./templates/flexGroup.vue";
import templateSlide from "./templates/slide.vue";
import { mixinsModuleCss } from "@/components/DiyNew/diy/mixins/index.js";
import moduleHeader from "@/components/DiyNew/diy/baseControl/moduleHeader/index.vue";
import { integralGoodslist } from "@/api/diy/goods/goods";

export default {
  name: "integralProduct",
  props: {
    propsData: {
      type: Object,
      default: {},
    },
  },
  mixins: [mixinsModuleCss],
  components: {
    templateDefault,
    templateFlexTwo,
    templateColumn,
    templateGroup,
    templateSlide,
    moduleHeader,
  },
  data() {
    return {
      goodsList: [],
    };
  },
  mounted() {
    console.log("组件挂载了：", this.propsData);
    this.getGoodsList();
  },
  watch: {},
  computed: {
    goodsItemSpace() {
      let out = this.propsData.params.goodsItemOutSpace || "0";
      let inner = this.propsData.params.goodsItemInnerSpace || "0";
      let css = {};
      out = out * 2;
      inner = inner * 2;
      if (out) {
        css["margin"] = `0 ${out}rpx ${out}rpx ${out}rpx`;
      }
      if (inner) {
        css["padding"] = `${inner}rpx`;
      }
      return css;
    },
    styleType() {
      return this.propsData.params.styleType;
    },
    heaerBgCss() {
      if (!this.propsData.params.headerBg) return "";
      let style = JSON.parse(JSON.stringify(this.propsData.params.headerBg));

      if (!style.useBackground) {
        return {
          background: "inherit",
        };
      }
      return style;
    },
  },
  methods: {
    editModuleHeader(e) {
      this.$emit("chooseMoudle", e);
    },
    async getGoodsList() {
      let goods = await integralGoodslist({
        status: 1,
        product_type: 4,
      });
      console.log(goods, "商品豆油撒");
      if (goods.code == 0) {
        let data = goods.data.data;
        this.goodsList = data;
      }
    },
    toModuleHeaderControl() {
      let data = Object.assign({}, this.propsData);
      data.controlComName = "editProductModuleHeader";
      this.$emit("chooseMoudle", data);
    },
  },
};
</script>

<style lang="scss" scoped>
.module-bg {
  width: 100%;
  height: 100%;
  z-index: -1;
  position: absolute;
  left: 0;
  top: 0;
}
.goods-show {
  width: 100%;
  font-family: PingFang SC;

  .goods-header {
    width: 100%;
    padding: 0px 12px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;

    .module-header {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .module-name {
        font-size: 16px;
        font-weight: 600;
        color: #262626;
        margin-bottom: 0;
      }
      .more {
        display: flex;
        align-items: center;
        font-size: 12px;
        font-weight: 400;
        color: #888888;
        margin-bottom: 0;
        line-height: 1;
        .iconfont {
          font-size: 12px;
          margin-left: 2px;
          transform: scale(0.8);
        }
      }
    }
    .item-hover {
      width: 100%;
      height: 100%;
      border: 1px solid #1890fc;
      position: absolute;
      left: 0;
      top: 0;
      display: none;
      .edit-box {
        width: 20px;
        height: 20px;
        background: #1890fc;
        border-radius: 0px 0px 0px 4px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        position: absolute;
        right: 0;
        top: 0;
        .iconfont {
          font-size: 18px;
          color: #ffffff;
        }
      }
    }
  }
  .goods-header:hover > .item-hover {
    display: block;
  }
  .goods-list {
    width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;

    .template-default {
      display: flex;
      flex-direction: column;
      align-items: center;
      .goods-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        position: relative;
        .goods-banner {
          width: 100%;
          height: 175px;
          background: #f2f2f2;
          border-radius: 5px 5px 0px 0px;
          display: flex;
          justify-content: center;
          align-items: center;
          img {
            width: 100%;
            height: 100%;
          }
          .default-img {
            width: 100px;
            height: 77px;
          }
        }
        .goods-info {
          width: 100%;
          .goods-name {
            margin-top: 4px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 600;
            color: rgba(29, 29, 29, 0.94);
            word-break: break-all;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2; /* 这里是超出几行省略 */
            overflow: hidden;
            margin-bottom: 0;
          }
          .price-box {
            display: flex;
            align-items: flex-end;
            margin-top: 6px;
            .price {
              font-size: 12px;
              font-family: PingFang SC;
              font-weight: 600;
              line-height: 17px;
              color: #fa2c1b;
              span:nth-child(2) {
                font-size: 19px;
              }
            }
            .origin-price {
              font-size: 12px;
              font-family: PingFang SC;
              font-weight: 400;
              line-height: 17px;
              color: #9b9b9b;
              text-decoration: line-through;
            }
          }
          .sales {
            font-size: 12px;
            font-family: PingFang SC;
            font-weight: 400;
            line-height: 17px;
            color: #9b9b9b;
            padding-bottom: 12px;
          }
          .buy-btn {
            position: absolute;
            right: 8px;
            bottom: 20px;
            width: 24px;
            height: 24px;
            background: #fa2c1b;
            border-radius: 8px;
            display: flex;
            justify-content: center;
            align-items: center;
            .iconfont {
              font-size: 19px;
              color: #ffffff;
            }
          }
        }
      }
    }
  }
  .goods-list-default {
    display: block;
  }
  .add-padding {
    padding-top: 12px;
    height: inherit;
  }
}
</style>
